[#assign PayMode = {"0" : "线下支付", "1" : "快钱在线支付", "2" : "浙商在线支付", "3" : "平安银行在线支付"}]
[#assign PayResult = {"1" : "支付凭证审核中", "3" : "待复核"}]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<title>订单详情</title>
<link href="/res/css/common/baseAzt.css" rel="stylesheet" type="text/css" />
<link href="/res/css/common/backheadfoot.css" rel="stylesheet" type="text/css" />
<link href="/res/css/common/backcommon.css" rel="stylesheet" type="text/css" />
<link href="/res/css/respective/order/back-order.css" rel="stylesheet">
<style type="text/css">
    .logisticsChok .cmdan .look .down {
        z-index: 99;
    }
    .fr>p span{
        display: inline-block;
        width: 85px;
        text-align: right;
        float: left;
    }
</style>
</head>
<body>
[#-- ispurchaser是否是采购商 --]
[#assign ispurchaser = Session.currentRole.roleType == 1]
<div class="warp [#if !ispurchaser]warp-supplier[/#if]">
    	[#include "/front/common/front_headAzt.html"]
         
         <div class="backcontent">
            <div class="back-main back-main-view">
            	<div class="inner">
      				<div class="alltitle">订单详情</div>
                    <div class="orderStatus">
                    	当前状态：<b>${orderStateMap[order.state?string]!}</b>
                        [#if !onlyFinance]
                            [#if ispurchaser]
                                [#if order.state == 3]
                                    <a href="/order/ship/product/${order.id!}" target="_blank" class="abtn">确认收货</a>
                                [/#if]
                                [#if order.state != 0 && order.state != 4 && unPayInfo?? && unPayInfo.totalPrice > 0]
                                    <a href="javascript:void(0)" onclick="goPay('${order.id!}', '${unPayInfo.id!}')" class="abtn">支付</a>
                                [/#if]
                            [#else]
                                [#if order.state == 1]
                                    <a href="javascript:void(0)" onclick="showModifyPriceWin(${order.id!}, '${order.totalPrice!}','${order.originalPrice!}')" class="abtn">修改价格</a>
                                [/#if]
                                [#if order.state != 0 && order.state != 4 && !order.ifBatchShip??]
                                    <a href="/order/ship/product/${order.id!}" target="_blank" class="abtn">立即发货</a>
                                [/#if]
                            [/#if]
                            [#if order.state == 1]
                                <a href="javascript:void(0)" onclick="showCancelOrderWin(${order.id!})">取消订单</a>
                            [/#if]
                            [#else]
                                [#if order.state != 0 && order.state != 4 && !order.ifBatchPay?? && unPayInfo??]
                                    <a href="javascript:void(0)" onclick="goPay('${order.id!}', '${unPayInfo.id!}')" class="abtn">支付</a>
                                [/#if]
                        [/#if]

                        [#if order.state == 0]
                            <p class="p1"><span><i>关闭类型：</i>[#if order.cancelUserType == 2]卖家取消订单[#elseif order.cancelUserType == 1]买家取消订单[/#if]</span>
                            [#if order.cancelReason??]<span><i>关闭原因：</i>${order.cancelReason!}[#if order.cancelInstr?? && order.cancelInstr != '']（${order.cancelInstr}）[/#if]</span>[/#if]
                            [#if order.cancelTime??]<span><i>关闭时间：</i> ${(order.cancelTime?string("yyyy-MM-dd HH:mm"))!}</span></p>[/#if]
                        [/#if]
                    </div>
                    
                    <div class="orderpayInfo">
                    	<h4>支付信息</h4>
                        <div class="cont">
                    	[#if orderPays?? && orderPays?size > 0 ]
                            [#list orderPays as orderPay]
                                [#if orderPay_index != 0]<div class="line">[/#if]
                                <table>
                                    <tbody>
                                        <tr>
                                            <td width="20%">
                                                <b>
                                                    [#if order.ifBatchPay?? && order.ifBatchPay==0]
                                                        一次性支付：
                                                    [#else]
                                                        第${orderPay_index+1}批：
                                                    [/#if]
                                                </b>
                                                应付金额：¥${orderPay.totalPrice?string('0.00')!}
                                            </td>
                                            [#--<td width="20%">
                                                支付流水号：${orderPay.payNumber!}
                                            </td>--]
                                            <td width="20%">
                                                安装币抵扣：¥${(orderPay.dePrice!0.00)?string('0.00')}
                                            </td>
                                            <td width="15%">
                                                实付金额：¥[#if orderPay.isDeco?? && orderPay.isDeco==1]${(orderPay.totalPrice-orderPay.dePrice!0)?string('0.00')}[#else]${orderPay.totalPrice!?string('0.00')}[/#if]
                                            </td>
                                            <td width="35%">
                                                实付时间：${(orderPay.payTime?string("yyyy-MM-dd HH:mm"))!}
                                                &nbsp;&nbsp;&nbsp;
                                                [#if orderPay.payMode??]
                                                ${PayMode[orderPay.payMode?string]!}
                                                    [#if orderPay.payMode == 0 && orderPay.proveImg??]
                                                        (<a href="javascript:viewPic('${orderPay.proveImg!}')">查看支付凭证</a>)
                                                    [/#if]
                                                [/#if]
                                            </td>
                                            <td width="10%">
                                                ${PayResult[orderPay.payResult?string]!}
                                            </td>
                                        </tr>
                                        [#if !orderPay_has_next]
                                        <tr id="unpaidTr">
                                            <td colspan="5"><p class="surplus"><b>剩余金额：</b><span class="orange" id="unpaid"></span></p></td>
                                        </tr>
                                        [/#if]
                                    </tbody>
                                </table>
                                [#if orderPay_index!=0]</div>[/#if]
                            [/#list]
                        [#else]
                            <table>
                            	<tbody>
                                	<tr>
                                    	<td width="50%"><span>暂无支付信息</span></td>
            						</tr>
                                </tbody>
                            </table>
                        [/#if]   
                        </div>
                    </div>
                    <!--<div class="orderpayInfo">-->
                    	<!--<h4>买方付款账户信息</h4>-->
                        <!--<div class="cont">-->
                            <!--<table>-->
                            	<!--<tbody>-->
                                    <!--[#if baccount??]-->
                                        <!--<tr>-->
                                            <!--<td><span>开户行名称：${baccount.bankName!}</span></td>-->
                                        <!--</tr>-->
                                        <!--<tr>-->
                                            <!--<td><span>账号名称：${baccount.acctName!}</span></td>-->
                                        <!--</tr>-->
                                        <!--<tr>-->
                                            <!--<td><span>账号：${baccount.hideRelatedAcctId!}</span></td>-->
                                        <!--</tr>-->
                                    <!--[#else]-->
                                        <!--<tr>-->
                                            <!--<td><span>无</span></td>-->
                                        <!--</tr>-->
                                    <!--[/#if]-->
                                <!--</tbody>-->
                            <!--</table>-->
                        <!--</div>-->
                    <!--</div>-->
                    <!--<div class="orderpayInfo">-->
                    	<!--<h4>卖方付款账户信息</h4>-->
                        <!--<div class="cont">-->
                            <!--<table>-->
                            	<!--<tbody>-->
                                    <!--[#if saccount??]-->
                                        <!--<tr>-->
                                            <!--<td><span>开户行名称：${saccount.bankName!}</span></td>-->
                                        <!--</tr>-->
                                        <!--<tr>-->
                                            <!--<td><span>账号名称：${saccount.acctName!}</span></td>-->
                                        <!--</tr>-->
                                        <!--<tr>-->
                                            <!--<td><span>账号：${saccount.hideRelatedAcctId!}</span></td>-->
                                        <!--</tr>-->
                                    <!--[#else]-->
                                        <!--<tr>-->
                                            <!--<td><span>无</span></td>-->
                                        <!--</tr>-->
                                    <!--[/#if]-->
                                <!--</tbody>-->
                            <!--</table>-->
                        <!--</div>-->
                    <!--</div>-->


                    <div class="orderInfomation logisticsChok">
                    	<h4>订单信息</h4>
                        <div class="backTab"><a href="#" class="on">收货信息</a><a href="#">物流信息</a></div>
                        <div class="backcont">
                            <div class="ibackcont">
                                <table>
                                    <tbody>
                                        <tr>
                                            <td width="50%"><span>姓名：</span>${order.receiptName!}</td>
                                            <td width="50%"><span>联系电话：</span>[#if order.receiptTel?? && order.receiptTel != '']${order.receiptTel!}[#else]${order.receiptPhone!}[/#if]</td>
                                        </tr>
                                        <tr>
                                            <td colspan="2"><span>收货信息：</span>${address.receiptProvinceName!} ${address.receiptCityName!} ${address.receiptAreaName!} ${address.receiptAddress!}</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                            <div class="ibackcont" style="display:none">
                                <table>
                                    <tbody>
                                    	[#if orderShips?size == 0]
                                    	    <tr>
		                                   		<td width="20%"><span>暂无物流信息</span></td>
		                                	</tr>
		                                [/#if]
										[#list orderShips as ordership]  
                                        	[#if ordership.shipState==1 || ordership.shipState==2]
	                                        	[#if ordership.shipType==1]
	                                        	<tr>
			                                        <td width="20%" colspan="2"><span>[#if order.ifBatchShip?? && order.ifBatchShip==1]第${ordership_index+1!}批次：&nbsp;[/#if]快递公司：</span>${ordership.companyName!}</td>
			                                        <td width="20%" colspan="3">
			                                            <div class="cmdan" style="height:21px">
			                                                <i style="color:#999">运单号码：</i>${ordership.expressNumber!}
			                                                <div class="look" data-shipid="${ordership.id!}">查看物流跟踪信息
				                                                <div class="down" id="detail${ordership.id!}">
				                                                    <em></em>
				                                                    <div class="dtitle">物流跟踪</div>
				                                                    <img class="image" src="/res/third/nice-validator/images/loading.gif" alt="loading"/>
				                                                </div>
			                                            	</div>
			                                            </div>
		                                        	</td>
	                                        	</tr>
	                                        	[#elseif ordership.shipType==2]
	                                        	<tr>
		                                        	<td width="20%">[#if order.ifBatchShip?? && order.ifBatchShip==1]<span>第${ordership_index+1!}批次：&nbsp;</span>[/#if]车辆配载</td>
		                                        	<td width="20%"><span>车牌号：&nbsp;</span>${ordership.plateNumber!}</td>
		                                        	<td width="20%"><span>配送人：&nbsp;</span>${ordership.contacts!}</td>
		                                        	<td width="20%"><span>手机号：&nbsp;</span>${ordership.contactTel!}</td>
		                                        	<td width="20%"><span>出发日期：&nbsp;</span>${ordership.shipTime?string("yyyy-MM-dd")}</td>
	                                        	</tr>
	                                        	[#elseif ordership.shipType==3]
	                                        	<tr>
		                                        	<td width="20%">[#if order.ifBatchShip?? && order.ifBatchShip==1]<span>第${ordership_index+1!}批次：&nbsp;</span>[/#if]自提</td>
		                                        	<td width="20%"><span>提货地点：&nbsp;</span>${ordership.pickAddress!}</td>
		                                        	<td width="20%"><span>联系人：&nbsp;</span>${ordership.contacts!}</td>
		                                        	<td width="20%"><span>手机号：&nbsp;</span>${ordership.contactTel!}</td>
		                                        	<td width="20%">&nbsp;</td>
	                                        	</tr>
	                                        	[/#if]
                                        	[#else]
                                        	<tr>
                                        		<td width="20%" colspan="5"><span>[#if order.ifBatchShip?? && order.ifBatchShip==1]第${ordership_index+1!}批次：&nbsp;[/#if]未发货，暂无物流信息</span></td>
                                        	</tr>
                                        	[/#if]
                                        [/#list]
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        [#if order.invoice == 2 || order.invoice == 3]
                        <div class="box">
                        	<h5>发票信息</h5>
                            <table>
                                <tbody>
                                    [#if order.invoice==2]
                                        <tr>
                                            <td width="50%"><span>发票类型：</span>增值税普通发票</td>
                                            <td width="50%"><span>发票抬头：</span>${order.taxTitle!}</td>
                                        </tr>
                                    [#elseif order.invoice==3]
                                        <tr>
                                            <td width="50%"><span>发票类型：</span>增值税专用发票</td>
                                        </tr>
                                        <tr>
                                            <td width="50%"><span>公司名称：</span>${topBuyerCompany.companyName!}</td>
                                            <td width="50%"><span>纳税人识别号：</span>${order.taxNumber!}</td>
                                        </tr>
                                        <tr>
                                            <td width="50%"><span>注册地址：</span>${order.taxAddress!}</td>
                                            <td width="50%"><span>注册电话：</span>${order.taxPhone!}</td>
                                        </tr>
                                        <tr>
                                            <td width="50%"><span>开户银行：</span>${order.taxOpenbank!}</td>
                                            <td width="50%"><span>开户账号：</span>${order.taxBankNumber!}</td>
                                        </tr>
                                    [/#if]
                                </tbody>
                            </table>
                        </div>
                        [/#if]
                    </div>
                    <div class="dataTable orderTable">
                        <div class="alltd">下单时间：${(order.ordertime?string("yyyy-MM-dd HH:mm"))!}　　订单号：${order.orderNumber!} &nbsp; &nbsp; &nbsp;
                            <div class="cname">卖家：${seller.companyName!}</div>
                        </div>
                        <table>
                            <thead>
                            <tr class="tdtitle">
                                <td width="55%"><p class="name font14" style="font-weight:bold">商品名称</p></td>
                                <td width="15%">单价</td>
                                <td width="15%">数量</td>
                                <td width="15%">小计</td>
                            </tr>
                            </thead>
                        </table>
                        <div style="max-height: 880px;overflow-y: auto;">
                            <table>
                                <tbody>
                                [#list productList as pro]
                                <tr>
                                    <td width="55%" style="position: relative;">
                                        <p class="name"  style="position: absolute;top: 25px;">
                                            <img src="[#if pro.picPath?? && pro.picPath != '']${pro.picPath?split(';')[0]}[/#if]" width="45px" height="45px" style="margin-right: 5px;" alt="">
                                        </p>
                                        <span class="introCar">
                                        <a href="/offer/${pro.productId!}.html" target="_blank" style="vertical-align: top;">
                                        ${pro.productName!}
                                         </a>
                                        <em title="${pro.skuStr!}">${pro.skuStr!}</em>
                                    </span>
                                    </td>
                                    <td width="15%">￥${pro.price!?string('0.00')}</td>
                                    <td width="15%">${pro.quantity!}</td>
                                    <td width="15%"><b class="orange">￥${pro.totalPrice!?string('0.00')}</b></td>
                                </tr>
                                [/#list]
                                </tbody>
                            </table>
                        </div>

                    </div>
                    <div class="orderviewDetail">
                    	<div class="fr">
                        	<p><span>总商品金额：</span><b>￥${order.originalPrice!?string('0.00')}</b></p>
                            <p><span>优惠金额：</span>-￥${(order.originalPrice-order.totalPrice)?string('0.00')}</p>
                            <p class="allprice">应付总额：<b class="orange">￥${order.totalPrice!?string('0.00')}</b></p>
                        </div>
                    	<div class="msgcont">留言内容：[#if order.message?? && order.message != '']${order.message!}[#else]无[/#if]</div>
                    </div>
                </div>
            </div>
         </div>
  		[#include "/front/common/front_footerAzt.html"]
    </div>

	<!-- 取消订单 -->
    <div class="tanbox tan-resetOrder" id="cancelOrderWin" style="display: none;">
        <input type="hidden" name="orderId" value="${order.id}">
        <div class="tanbg"></div>
        <div class="box">
            <div class="title"><span class="closed"></span>取消订单</div>
            <div class="cont">
                <p>请选择您取消订单的原因：</p>
                <ul class="fix">
				[#if ispurchaser]
                    <li><label><span class="radioModel radioModelon"><input type="radio" name="cancelReason" checked="checked" value="信息有误，重新下单"/></span> 信息有误，重新下单</label></li>
                    <li><label><span class="radioModel"><input type="radio" name="cancelReason" value="不需要货品了"/></span> 不需要货品了 </label></li>
                    <li><label><span class="radioModel"><input type="radio" name="cancelReason" value="付款遇到问题"/></span> 付款遇到问题  </label></li>
                    <li><label><span class="radioModel"><input type="radio" name="cancelReason" value="其他"/></span> 其他 </label></li>
				[#else]
                    <li><label><span class="radioModel radioModelon"><input type="radio" name="cancelReason" checked="checked" value="无法备齐货"/></span> 无法备齐货 </label></li>
                    <li><label><span class="radioModel"><input type="radio" name="cancelReason" value="不是有效的订单"/></span> 不是有效的订单 </label></li>
                    <li><label><span class="radioModel"><input type="radio" name="cancelReason" value="货款支付问题"/></span> 货款支付问题  </label></li>
                    <li><label><span class="radioModel"><input type="radio" name="cancelReason" value="其他"/></span> 其他 </label></li>
				[/#if]
                </ul>
                <div class="tarea">
                    <textarea placeholder="补充说明" name="cancelInstr" style="resize: vertical; outline: none;" onkeyup="checkCancelInstr()"></textarea>
                    <p>0/500</p>
                </div>
                <p class="error" style="display: none;"><i></i>请选择一个原因</p>
                <div class="btn">
                    <a href="javascript:void(0)" onclick="cancelOrder()">确定</a>
                    <a href="javascript:void(0)" onclick="$('#cancelOrderWin').hide();">取消</a>
                </div>
            </div>
        </div>
    </div>

<!-- 修改价格弹出框 -->
<div class="tanbox tan-editprice" id="modifyPriceWin" style="display: none;">
    <input type="hidden" name="orderId">
    <input type="hidden" name="maxPrice">
    <div class="tanbg"></div>
    <div class="box" style="width: 450px;">
        <div class="title"><span class="closed"></span>修改价格</div>
        <div class="cont">
            <div class="inputDiv">
                <input type="text" placeholder="输入价格" name="price"/> 应付总额：<span class="orange"></span></div>
            <div class="btn btn-left">
                <a href="javascript:void(0)" onclick="modifyPrice()">确定</a>
                <a href="javascript:void(0)" onclick="$('#modifyPriceWin').hide()">取消</a>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript" src="/res/js/structure/struture.js"></script>
<script type="text/javascript" src="/res/third/laydate/laydate.js"></script>
<script type="text/javascript" src="/res/third/layer/layer.js"></script>
<script type="text/javascript" src="/res/js/common/util.js"></script>
<script type="text/javascript" src="/res/third/nice-validator/jquery.validator.min.js?local=zh-CN"></script>
<script type="text/javascript" src="/res/js/common/tppl.js"></script>
<script type="text/javascript">
	$(function(){
		//收货信息 物流信息切换
		$('.orderInfomation .backTab a').click(function(){
			$(this).siblings('a').removeClass('on').end().addClass('on');
			$(this).parent().next().find('.ibackcont').hide().eq($(this).index()).show();
			return false;	
		});

        $('.radioModel input').click(function() {
            if(this.checked){
                $(this).parents('ul').find('.radioModel').removeClass('radioModelon');
                $(this).parent().addClass('radioModelon');
            }
        })
        $('.tan-resetOrder .closed').click(function(){
            $(this).parents('.tanbox').hide();
        })

        $('.tanbox .closed').click(function(){
            $(this).parents('.tanbox').hide();
        })
	})
	
	$(document).ready(function(){
			//剩余金额
			var unpaid = ${order.totalPrice};
			[#list orderPays as orderPay]
				unpaid = sub(unpaid, ${orderPay.totalPrice});
			[/#list]
			$("#unpaid").text("￥" + unpaid.toFixed(2));
			//剩余货物金额
			var unpaidProduct = ${order.totalPrice};
			[#list orderShips as orderShip]
				unpaidProduct = sub(unpaidProduct, ${orderShip.totalPrice});
			[/#list]
			$("#unpaidProduct").text("￥" + unpaidProduct.toFixed(2));
			if(unpaid <= 0) {
				$("#unpaidTr").remove();
			};
			if(unpaidProduct<=0 || '${isShipEnd?string}' == 'true'){
				$("#unpaidProductTr").remove();
			}
	})
	
	function getKuaidiInfo(shipid){
		$.ajax({
			type : "post",
			dataType : "json",
			url : "/order/kuaidi",
			data : {shipId:shipid},
			success : function(data) {//成功的时候调用
				if(data && data.length>0){
					var htmltext= "<ul class='wuliu'>";
					for(var i = 0; i < data.length; i++){
						if (i==0) {
							htmltext+= "<li class='on'><p>"+new Date(data[i].time).Format("yyyy-MM-dd hh:mm:ss")+"</p><p>"+data[i].context+"</p></li>";
						}
						else {
							htmltext+= "<li><p>"+new Date(data[i].time).Format("yyyy-MM-dd hh:mm:ss")+"</p><p>"+data[i].context+"</p></li>";
						}
					}
					htmltext+= "</ul>";
					$("#detail"+shipid).find(".image").remove();
					$("ul").remove(".wuliu");
					$("div").remove(".wuliu");
					$("#detail"+shipid).append(htmltext);	
				}else{
					var htmltext = "<div class='nolog wuliu'>暂未查询到物流信息，可到物流公司官网查询～</div>";
					$("#detail"+shipid).find(".image").remove();
					$("ul").remove(".wuliu");
					$("div").remove(".wuliu");
					$("#detail"+shipid).append(htmltext);
				}
			}
		});
	}
	
	
	Date.prototype.Format = function (fmt) {
	    var o = {
	        "M+": this.getMonth() + 1, //月份 
	        "d+": this.getDate(), //日 
	        "h+": this.getHours(), //小时 
	        "m+": this.getMinutes(), //分 
	        "s+": this.getSeconds(), //秒 
	        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
	        "S": this.getMilliseconds() //毫秒 
	    };
	    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	    for (var k in o)
	    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	    return fmt;
	}
	
	$(".look").hover(function(){
		var shipid=$(this).attr("data-shipid");
		getKuaidiInfo(shipid);
	},function(){
		
	})



    function showCancelOrderWin() {
        $('#cancelOrderWin .error').hide();
        $('#cancelOrderWin input[name=cancelReason]:eq(0)').prop('checked', true);
        $('#cancelOrderWin input[name=cancelReason]:eq(0)').click();
        $('#cancelOrderWin textarea[name=cancelInstr]').val('');
        checkCancelInstr();
        $('#cancelOrderWin').show();
    }

    //补充说明校验&&字数显示
    function checkCancelInstr() {
        var cancelReason = $('#cancelOrderWin input[name=cancelReason]:checked').val();
        var cancelInstr = $('#cancelOrderWin textarea[name=cancelInstr]').val();
        if(cancelReason == '其他' && cancelInstr == '') {
            $('#cancelOrderWin .error').html('<i></i>请输入补充说明');
            $('#cancelOrderWin .error').show();
        } else {
            if(cancelInstr.length > 500) {
                $('#cancelOrderWin .error').html('<i></i>补充说明不能超过500字');
                $('#cancelOrderWin .error').show();
            } else {
                $('#cancelOrderWin .error').hide();
            }
        }
        $('#cancelOrderWin textarea[name=cancelInstr]').next().html(cancelInstr.length + '/500');   //字数实时显示
    }

    function cancelOrder() {
        var orderId = $('#cancelOrderWin input[name=orderId]').val();
        var cancelReason = $('#cancelOrderWin input[name=cancelReason]:checked').val();
        var cancelInstr = $('#cancelOrderWin textarea[name=cancelInstr]').val();
        if(cancelReason == '') {
            $('#cancelOrderWin .error').html('<i></i>请选择一个原因');
            $('#cancelOrderWin .error').show();
            return;
        }
        checkCancelInstr();
        if($('#cancelOrderWin .error').is(':visible')) {
            return;
        }
        $.ajax({
            url : '/order/cancelOrder',
            type : 'post',
            dataType : 'json',
            data : {orderId : orderId, cancelReason : cancelReason, cancelInstr : cancelInstr},
            success : function(data) {
                if(data.success) {
                    layer.alert("取消订单成功", function() {
						location.reload();
					});
                } else {
                    layer.msg("取消失败");
                }
            }
        });
    }

    function showModifyPriceWin(orderId, totalPrice, originalPrice) {
        $('#modifyPriceWin input[name=orderId]').val(orderId);
        $('#modifyPriceWin input[name=maxPrice]').val(originalPrice);
        $('#modifyPriceWin span.orange').html('￥' + totalPrice);
        $('#modifyPriceWin').show();
    }

    //修改价格
    function modifyPrice() {
        var orderId = $('#modifyPriceWin input[name=orderId]').val();
        var maxPrice = $('#modifyPriceWin input[name=maxPrice]').val();
        var price = $('#modifyPriceWin input[name=price]').val();
        if(price == '') {
            layer.msg('请输入价格');
            return;
        }
        if(!/^([1-9]\d*|0)(\.\d{1,2})?$/.test(price)) {
            layer.msg('请输入正确的价格，最多保留小数点2位');
            return;
        }
        if(Number(price) <= 0 || Number(price) > maxPrice) {
            layer.msg('请输入正确的价格，不能超过' + maxPrice);
            return;
        }
        $.ajax({
            url : '/order/modifyPrice',
            type : 'post',
            dataType : 'json',
            data : {orderId : orderId, price : price},
            beforeSend : function() {
                layer.load(2, {shade: 0.1});
            },
            success : function(data) {
                if(data.success) {
                    layer.alert("操作成功", {closeBtn: 0}, function() {
                        location.reload();
                    });
                } else {
                    layer.msg(data.msg);
                }
            },
            complete : function() {
                layer.closeAll('loading');
            }
        });
    }
    
    function viewPic(pic) {
    	var pics = pic.split(',');
    	var data = [];
    	for(var i=0;i<pics.length;i++){
    		data.push({alt:"交易凭证", src:pics[i]});
    	}
        layer.photos({
            photos: {
                "data": data
            },
            anim: 0,
            closeBtn : 1
        });
    }

    function goPay(orderId, payId) {
    [#if ispurchaser]
        [#if isAdmin || onlyFinance]
            window.open('/order/pay_on/' + orderId + '/' + payId);
        [#else]
            layer.alert('您没有财务管理权限，请联系财务人员进行操作');
        [/#if]
    [/#if]
    }
</script>
</body>
</html>
